﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Pibby.Core.Tests
{
	[TestClass]
	public class HumanReadableDateInterpreterTests
	{
		[TestMethod]
		public void MinutesAreFormattedCorrectly()
		{
			Assert.AreEqual("1 minute ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddMinutes(-1)));
			Assert.AreEqual("5 minutes ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddMinutes(-5)));
			Assert.AreEqual("59 minutes ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddMinutes(-59)));
		}

		[TestMethod]
		public void HoursAreFormattedCorrectly()
		{
			Assert.AreEqual("1 hour ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddHours(-1)));
			Assert.AreEqual("2 hours ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddHours(-2)));
			Assert.AreEqual("23 hours ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddHours(-23)));
		}

		[TestMethod]
		public void YesterdayIsFormattedCorrectly()
		{
			Assert.AreEqual("Yesterday", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-1)));
		}

		[TestMethod]
		public void DaysLastWeekAreFormattedCorrectly()
		{
			Assert.AreEqual("2 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-2)));
			Assert.AreEqual("3 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-3)));
			Assert.AreEqual("4 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-4)));
			Assert.AreEqual("5 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-5)));
			Assert.AreEqual("6 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-6)));
			Assert.AreEqual("7 days ago", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today.AddDays(-7)));
		}

		[TestMethod]
		public void InLastMonthIsFormattedCorrectly()
		{
			DateTime refDate = new DateTime(2009, 10, 1);

			Assert.AreEqual("1 week ago", HumanReadableDateInterpreter.HowLongAgo(refDate.AddDays(-9), refDate));
			Assert.AreEqual("2 weeks ago", HumanReadableDateInterpreter.HowLongAgo(refDate.AddDays(-15), refDate));
			Assert.AreEqual("3 weeks ago", HumanReadableDateInterpreter.HowLongAgo(refDate.AddDays(-22), refDate));
		}

		[TestMethod]
		public void OlderPeriodsAreFormattedCorrectly()
		{
			DateTime refDate = new DateTime(2009, 10, 1);
			DateTime sixMonthsAgo = refDate.AddMonths(-6);
			DateTime lastYear = refDate.AddYears(-1);

			Assert.AreEqual(sixMonthsAgo.ToLongDateString(), HumanReadableDateInterpreter.HowLongAgo(sixMonthsAgo, refDate));
			Assert.AreEqual(lastYear.ToLongDateString(), HumanReadableDateInterpreter.HowLongAgo(lastYear, refDate));
		}

		[TestMethod]
		public void UninitializedDateIsUnknown()
		{
			Assert.AreEqual("Unknown", HumanReadableDateInterpreter.HowLongAgo(DateTime.MinValue));
		}

		[TestMethod]
		public void TodayIsFormattedCorrectly()
		{
			Assert.AreEqual("Today", HumanReadableDateInterpreter.HowLongAgo(DateTime.Today));
		}
	}
}
